#ifndef __DRV_MISC_H__
#define __DRV_MISC_H__

#include "os_sys.h"
#include <stdbool.h>
#include <stdint.h>


/*状态灯close*/
#define STATUS_LAMP_CLOSE (0)
/*红色*/
#define STATUS_LAMP_RED (0x1 << 2)
/*蓝色*/
#define STATUS_LAMP_BLUE (0x1 << 0)
/*绿色*/
#define STATUS_LAMP_GREEN (0x1 << 1)
/*黄色*/
#define STATUS_LAMP_YELLOW (STATUS_LAMP_RED | STATUS_LAMP_GREEN)
/*青色*/
#define STATUS_LAMP_CYAN (STATUS_LAMP_BLUE | STATUS_LAMP_GREEN)
/*紫色*/
#define STATUS_LAMP_MAGENTA (STATUS_LAMP_RED | STATUS_LAMP_BLUE)
/*白色*/
#define STATUS_LAMP_WHITE                                                      \
  (STATUS_LAMP_RED | STATUS_LAMP_BLUE | STATUS_LAMP_GREEN)
/*红绿蓝交替色*/
#define STATUS_LAMP_VARIETY (1 << 4)

#define STATUS_LAMP_FLICKER_FOREVER (uint32_t) - 1
#define STATUS_LAMP_FLICKER_LIGHT_MS 200
/*设备时间信息*/
typedef struct {
  int8_t time_zone;
  uint16_t year;
  uint8_t month;
  uint8_t day;
  uint8_t hour;
  uint8_t minute;
  uint8_t second;
  uint16_t millisecond;
} __attribute__((aligned(4))) DevTime_t;

/*get current time, in seconds from 1970.1.1*/
int DrvMisc_GetSec(uint64_t *time);
uint32_t DrvMisc_GetSysTick(void);
/*get restore key if is restore state or not*/
bool DrvMisc_IsRestore();

/*get restore key if is debug state or not*/
bool DrvMisc_IsDebug();

/*when restore or debug mode is detected, call the function to
  clear restore flag*/
void DrvMisc_ClearRestoreFlag();

/*get door close switch state*/
bool DrvMisc_IsBattDoorOpen();
/*get battery capacity by voltage from ADC*/
/*cap: battery capacity, in percentage*/
/*volt: battery voltage, in mV*/
int DrvMisc_GetBattInfoByQV(uint8_t *cap, uint16_t *volt);
int DrvMisc_SetStateLightFlicker(uint8_t color_mask, uint32_t light_ms,
                                 uint32_t itv_ms, uint32_t flicker_tick,
                                 bool sync);
void DrvMisc_SetDebugLight();
void DrvMisc_SetRestoreLight();
void DrvMisc_SetSelfTestLight();
void DrvMisc_SetFactoryModeLight();
/*set radar power on*/
/*on, true: power on, false, power off*/
int DrvMisc_SetRadarPower(bool on);

int DrvMisc_GetTime(DevTime_t *cur_time);
#endif
